<?php
require_once('db.php');
require_once('utils.php');

session_check();
if (empty($user)){
    print "acceso restringido";
    exit;
}
$error = '';

$email = know_user_attr($user, "email");
$location = know_user_attr($user, "location");
$avatar = know_user_attr($user, "avatar");
if($_POST){
    if(!empty($_FILES['avatar']['tmp_name'])){
        $error .= image_upload($user, $_FILES);
    }

    $location = $_POST['location'];
    $nemail = $_POST['email'];
    $nlocation = $_POST['location'];
    $pass0 = $_POST['pass0'];
    $pass1 = $_POST['pass1'];
    $pass2 = $_POST['pass2'];

    $error .= edit_profile($user, $avatar, $nemail, $location, $pass0, $pass1, $pass2);
    if($error == '')
        header("Location: index.php");
}
?>

<!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
  <head>
    <title>Sweetter 2.0</title>
    <link rel="stylesheet" type="text/css" href="css/estilo.css" />
  <link rel="icon" href="img/favicon.ico" type="image/vnd.microsoft.icon">
    <script type="text/javascript" src="js/jquery-1.2.1.min.js"></script>
    <script type="text/javascript" src="js/profile.js"></script>
    <meta http-equiv=content-type content="text/html; charset=UTF-8">
  </head>
  <body>
<?php

show_header("Sweetter 2.0");

    print '<div id="head"><h3><span id="user">'.$user.'</span> Profile:</h3></div>';
    if (!empty($error)) {
	    echo '<div class="error">'.$error.'</div>';
}
?>
<p/>
<div id="edit_profile">
<form method="POST" enctype="multipart/form-data" action="edit_profile.php">
<label for="avatar">avatar:</label>
<?php
if (!empty($avatar))
    print '<img src="'.$avatar.'"/>';
?>
<input type="hidden" name="MAX_FILE_SIZE" value="100000"/>
<input type="file" name="avatar" id="avatar"/>
<label for="email" id="lemail">email:</label>
<input type="text" value="<?php print $email; ?>" id="email" name="email"/>
<label for="location" id="llocation">location:</label>
<input type="text" value="<?php print $location; ?>" id="location" name="location"/>
<fieldset>
<legend>Change Password</legend>
<label for="pass0" id="lpass0">Password Actual:</label>
<input type="password" value="" id="pass0" name="pass0"/>
<label for="pass1" id="lpass1">Nuevo Password:</label>
<input type="password" value="" id="pass1" name="pass1"/>
<label for="pass2" id="lpass2">Nuevo Password:</label>
<input type="password" value="" id="pass2" name="pass2"/>
</fieldset>
<input type="submit" value="send"/>
</form>
</div>

	<?php pie();?>
  </body>
</html>
